﻿@{
    ViewBag.Title = "回访";
    Layout = "~/Areas/IM/Views/Shared/_Layout.cshtml";
}

@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            DisableBackspace();
            RevistMainGrid();
        });
        $(window).resize(function () {
            $.setGridWithSearchBar("#TableForm", "#tbb", "#RevistMain");
        });

        var EditRowID ="";
        var EditRowDate = new Date();

        function RevistMainGrid() {
            $('#RevistMain').datagrid({
                width: 'auto',
                height: 'auto',
               // fitColumns: true, //真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
                loadMsg: '数据加载中,请稍后……',
                url: '@Url.Content("~/DD/Revisit/GetRevistMain")',
                striped: true,
                singleSelect: true,
                pagination: true,//启用分页，默认每页10行
                rownumbers: true,//显示页码，默认 提供 10 - 50 的页容量选择下拉框
                pageSize: 15,//设置 页容量5
                pageList: [10, 15, 20],//设置 页容量下拉框
                frozenColumns: [[
                    { field: "ID", hidden: true },
                     {
                         field: "detail", title: "明细", width: '6%', align: "center",
                         formatter: function (value, row, index) {
                             var ifOperated = -1;
                             return '<a  class="linkURLcls" onclick="openDetailURL(\'' + row.ID + '\',\'' + ifOperated + '\');"  href="javascript:void(0)">明细</a>';
                         }
                     },
                      {
                          field: "deletez", title: "撤销", width: '6%', align: "center",
                          formatter: function (value, row, index) {
                             
                              return '<a  id="adelete" class="linkURL" onclick="deleteDetailURL(\'' + row.ID + '\');"  href="javascript:void(0)">撤销</a>';
                          }
                      },
                         {
                             field: "CompleteRate", title: "回访进度", width: '12%', align: "center",
                             formatter: formatProgress
                         },
                      { field: "CompleteNumber", title: "已回访", width: '4%', align: "center" },
                    { field: "UnfinishedNumber", title: "未完成", width: '4%', align: "center" },
                        { field: "FillDate", title: "任务日期", width: '9%', align: "center", formatter: $.formatDate },
                    { field: "FillPerson", title: "填报人", width: '6%', align: "center" },
                    { field: "FillDepartment", title: "填报部门", width: '9%', align: "center" },
                       { field: "FillTime", title: "填报时间", width: '13%', align: "center", formatter: $.formatTime },
                    { field: "LastModifier", title: "最后修改", width: '6%', align: "center" },
                    { field: "RevisitDeclare", title: "报表说明", width: '32%', align: "center" },

                ]],
                toolbar: [
                  {
                      id: 'btnAdd',
                      text: '新增任务',
                      iconCls: 'icon-add',
                      handler: function () {
                          
                          $('#RevisitAddTask').dialog('open');
                         // EditRowDate = "";
                           initPickTaskGrid();
                           
                      }
                  }, '-',
                    {
                        id: 'btnAdd',
                        text: '继续添加',
                        iconCls: 'icon-add',
                        handler: function () {
                            var row = $('#RevistMain').datagrid('getSelected');
                            if (row) {
                                 
                                EditRowID = row.ID;
                                //EditRowDate = "2015 - 7 - 22";                     
                             
                               EditRowDate = $.formatDate(row.FillDate, row);
                              
                                $('#RevisitAddTask').dialog('open');
                                initPickTaskGrid();
                            }
                            else {
                                $.messager.alert('系统提示', '请选择要修改的数据行！');
                            }
                        }
                    }, '-',
                   {
                       id: 'btnCheck',
                       text: '查看已回访',
                       iconCls: 'icon-search',
                       handler: function () {
                           var row = $('#RevistMain').datagrid('getSelected');
                           if (row) {
                               var rowid = row.ID;
                               var ifOperated = 1;
                               openDetailURL(rowid, ifOperated);
                           }
                           else {
                               $.messager.alert('系统提示','请选择要查看的数据行！');
                           }
                       }
                   }
                ],

                onLoadSuccess: function (data) {

                    $('.linkURLcls').linkbutton({
                        text: '明细',
                        plain: true,
                        iconCls: 'icon-search'
                    });
                    $('.linkURL').linkbutton({
                        text: '撤销',
                        plain: true,
                        iconCls:'icon-custom-cJinYong'
                    });
                }

            });
            $.setGridWithSearchBar("#TableForm", "#tbb", "#RevistMain");
        }

        function openDetailURL(rowid, ifOperated)
        {
            var url = '@Url.Content("~/DD/Revisit/RevisitOperateDetailList/?RowID=")' + rowid +'&ifOperated=' +encodeURIComponent(ifOperated);
            window.open(url);
        }

        function deleteDetailURL(deleterowID) {
            document.getElementById('adelete').disabled = true;
            $.ajax({
                type: 'POST',
                url: '@Url.Content("~/DD/Revisit/deleteRevisit")',
                data:
                    {
                       
                        deleteRowID: deleterowID
                       
                    },
                dataType: "json",
                success: function (jsData) {
                    $.handleJsonResult(jsData, function () {
                       // Materials.length = 0;
                        $("#RevistMain").datagrid("reload");
                        document.getElementById('adelete').disabled = false;
                      //  EditRowID = "";
                    }
                    //, function () {
                        //$('#btnDelivery').linkbutton('enable');
                    //}
                    );
                }
            });


        }

        //实现百分比效果
        function formatProgress(value) {
            if (value) {
                var s = '<div style="width:100%;border:1px solid #ccc">' +
		    			'<div style="width:' + value + '%;background:#BCEE68;color:#262626">' + value + '%' + '</div>'
                '</div>';
                return s;
            } else {
                return '';
            }
        }

    </script>
}
<div id="TableForm" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:'回访',iconCls:'icon-custom-cPrice'">
        <div id="tbb" style="padding: 5px; height: auto">
        </div>
        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="RevistMain" border="0"></table>
        </div>
    </div>
</div>
@Html.Partial("~/Areas/DD/Views/Revisit/RevisitAddList.cshtml")
@Html.Partial("~/Areas/DD/Views/Revisit/RevisitAddMain.cshtml")